package com.xjy.service;

import com.github.pagehelper.PageHelper;
import com.xjy.dao.cartMapper;
import com.xjy.pojo.Cart;

import java.util.List;

public class cartServiceImpl implements cartService{
    private cartMapper cartMapper;

    public void setCartMapper(com.xjy.dao.cartMapper cartMapper) {
        this.cartMapper = cartMapper;
    }

    @Override
    public int addCart(Cart cart) {
        return cartMapper.addCart(cart.getCid(),cart.getUid(),cart.getPath().getPid(),cart.getNum());
    }

    @Override
    public List<Cart> getCartList(int uid,Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return cartMapper.getCartList(uid);
    }

    @Override
    public int deleteCart(String cid) {
        return cartMapper.deleteCart(cid);
    }

    @Override
    public int updateCart(String cid, int num) {
        return cartMapper.updateCart(cid, num);
    }

    @Override
    public Cart getExistCart(int uid, String pid) {
        List<Cart> cartList = cartMapper.getCartList(uid);
        for (Cart cart : cartList) {
            if (cart.getPath().getPid().equals(pid)) {
                return cart;
            }
        }
        return null;
    }
}
